package com.hulk.ratel.manage.commonutil;


import com.hulk.ratel.common.constant.enums.BussErrCode;
import com.hulk.ratel.common.util.SpringContextHolder;
import com.hulk.ratel.manage.bo.ErrcodeConvertBO;
import com.hulk.ratel.manage.commoncache.ErrCodeConvertCache;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by hulk on 2017/6/15.
 * ErrorConvertUtil
 */
@Slf4j
@UtilityClass
public class ErrorConvertUtil {


    /**
     * 错误码转换
     *
     * @param orgCode
     * @param respCode  机构返回错误码
     * @return
     */
    public  ErrcodeConvertBO convertErrCode(String orgCode,String respCode) {

        ErrCodeConvertCache  errCodeConvertCache =   SpringContextHolder.getBean(ErrCodeConvertCache.class);
        ErrcodeConvertBO errCode =   errCodeConvertCache.findErrCodeConvert( orgCode, respCode);


        if (errCode == null) {
            log.error("支付机构返回错误码,在平台未找到对应册错误码：orgCode:{},respCode:{}", orgCode, respCode);
            ErrcodeConvertBO respErr = new ErrcodeConvertBO();
            respErr.setRespCode(BussErrCode.E_999999.getErrCode());
            respErr.setRespDesc(BussErrCode.E_999999.getErrDesc());
            return respErr;
        }
        return errCode;
    }
}
